package com.smec.remes.module.submit.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.smec.moblie.BR;
import com.smec.moblie.R;
import com.smec.moblie.databinding.ItemBackBinding;
import com.smec.remes.base.SmecBaseRecyclerViewHolder;
import com.smec.remes.bean.SubmitDetailsConfirme;

import java.util.ArrayList;

/**
 * Created by xupeizuo on 2017/12/24.
 */

public class SmecBackAdapter extends RecyclerView.Adapter<SmecBaseRecyclerViewHolder> {

    private Context mContext;

    public SmecBackAdapter(Context context) {
        this.mContext=context;
    }

    private ArrayList<SubmitDetailsConfirme> arrayList=new ArrayList<>();

    public void setArrayList(ArrayList<SubmitDetailsConfirme> arrayList) {
        this.arrayList = arrayList;
        notifyDataSetChanged();
    }

    @Override
    public SmecBaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemBackBinding itemBackBinding= DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.item_back,parent,false);
        SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new SmecBaseRecyclerViewHolder(itemBackBinding.getRoot());
        smecBaseRecyclerViewHolder.setBinding(itemBackBinding);
        smecBaseRecyclerViewHolder.setViewType(viewType);
        return smecBaseRecyclerViewHolder;
    }

    @Override
    public void onBindViewHolder(SmecBaseRecyclerViewHolder holder, int position) {
        ItemBackBinding itemBackBinding=(ItemBackBinding)holder.getBinding();
        itemBackBinding.setVariable(BR.back,arrayList.get(position));
        if(TextUtils.isEmpty(arrayList.get(position).getFlag())){
            itemBackBinding.llShouhuoTime.setVisibility(View.GONE);
        }else {
            itemBackBinding.llShouhuoTime.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }
}
